import { Recommend } from '@/models/recommend'
import { getResource, getSongs } from '@/utils/api'
import { defineStore } from 'pinia'

export const recommend = defineStore('recommend', {
    state: () => {
        return {
            rem: JSON.parse(localStorage.getItem("recommend")!),
            tomorrow: Number(localStorage.getItem("tomorrow"))
        }
    },
    actions: {
        async getRecommend() {
            let today = new Date().getDate()
            if (today !== this.tomorrow) {
                let { code, recommend } = await getResource()
                if (code == 200) {
                    this.rem = recommend
                    localStorage.setItem("recommend", JSON.stringify(this.rem))
                    this.tomorrow = new Date().getDate()
                    // console.log(typeof this.tomorrow)
                    localStorage.setItem("tomorrow", this.tomorrow.toString())
                }
            }
        },
        async getsongs() {
            let data = await getSongs()
            console.log(data)
        }
    },
    getters: {}
})

